package com.whty.module.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.whty.common.annotation.Log;
import com.whty.common.enums.BusinessType;
import com.whty.module.domain.DocFile;
import com.whty.module.service.IDocFileService;
import com.whty.web.core.base.BaseController;
import com.whty.framework.web.page.TableDataInfo;
import com.whty.common.base.AjaxResult;
import com.whty.common.utils.ExcelUtil;

/**
 * 文件 信息操作处理
 * 
 * @author mario
 * @date 2018-12-06
 */
@Controller
@RequestMapping("/module/docFile")
public class DocFileController extends BaseController
{
    private String prefix = "module/docFile";
	
	@Autowired
	private IDocFileService docFileService;
	
	@RequiresPermissions("module:docFile:view")
	@GetMapping()
	public String docFile()
	{
	    return prefix + "/docFile";
	}
	
	/**
	 * 查询文件列表
	 */
	@RequiresPermissions("module:docFile:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(DocFile docFile)
	{
		startPage();
        List<DocFile> list = docFileService.selectDocFileList(docFile);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出文件列表
	 */
	@RequiresPermissions("module:docFile:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DocFile docFile)
    {
    	List<DocFile> list = docFileService.selectDocFileList(docFile);
        ExcelUtil<DocFile> util = new ExcelUtil<DocFile>(DocFile.class);
        return util.exportExcel(list, "docFile");
    }
	
	/**
	 * 新增文件
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存文件
	 */
	@RequiresPermissions("module:docFile:add")
	@Log(title = "文件", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(DocFile docFile)
	{		
		return toAjax(docFileService.insertDocFile(docFile));
	}

	/**
	 * 修改文件
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		DocFile docFile = docFileService.selectDocFileById(id);
		mmap.put("docFile", docFile);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存文件
	 */
	@RequiresPermissions("module:docFile:edit")
	@Log(title = "文件", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(DocFile docFile)
	{		
		return toAjax(docFileService.updateDocFile(docFile));
	}
	
	/**
	 * 删除文件
	 */
	@RequiresPermissions("module:docFile:remove")
	@Log(title = "文件", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(docFileService.deleteDocFileByIds(ids));
	}
	
}
